//
//  GETestRenderAppDelegate.m
//  GETestRender
//
//  Created by Quoc Dung Chu on 19/07/11.
//  Copyright Paris 6 2011. All rights reserved.
//

#import "GETestRenderAppDelegate.h"
#import "EAGLView.h"

#include "GEList.h"
#include "GEOrderedTree.h"
#include "DLTrees.h"
#include "DLTreesTest.h"

using namespace game_engine::core;

@implementation GETestRenderAppDelegate

@synthesize window;
@synthesize glView;

- (NSString*) toString:(CTree<int>*) otree level:(int&) level
{
	NSString* levelSpace = @"";
	for (int i = 0; i<level; i++) {
		levelSpace = [NSString stringWithFormat:@"%@_",levelSpace];
	}
	
	if(!otree) return  [NSString stringWithFormat:@"%@vide",levelSpace];
	
		int newLevel = level+1;
	return([NSString stringWithFormat:@"%@%d\n%@\n%@",levelSpace,otree->root()->element(),
			[self toString:otree->root()->left() level:newLevel],
			[self toString:otree->root()->right() level:newLevel]]);
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions   
{
	CLinkedList<int>* list = new CLinkedList<int>();
	list->push_front( 1);
	list->push_front( 2);
	list->push_front( 3);
	list->push_front( 4);
	list->push_back( -1);
	list->push_back( -2);
	list->insert_after(list->end()->Prev->Prev, 0);
	NSLog(@"size %d",list->size());
	
	list->erase(list->begin()->Next->Next);
	NSLog(@"size %d",list->size());
	SLKNode<int>* node = list->begin();
	while (node) {
		NSLog(@"element %d",node->Element);
		node = node->Next;
	}
	delete list;
	//---------
	//test tree
	//CTree<int>* tree = new CTree<int>();
	
	COrderedTree<int>* otree = new COrderedTree<int>();
	
	otree->add(10);
	otree->add(1);
	otree->add(2);
	otree->add(3);
	otree->add(4);
	otree->add(5);
//	otree->add(6);
//	otree->add(7);
	
	int level = 0;
	NSString* s = [self toString:otree level:level];
    NSLog(@"%@",s);
	
//	CTNode<int>* root = otree->root()->left()->root()->left()->root();
//    NSLog(@"root of otree %d",root->element());
	
	//NSLog(@"smallest tree of root %d",root->smallestTree());
    //NSLog(@"root of smallest tree of root %d",root->smallestTree()->root()->element());
	delete otree;
    
    CTreesTest* test = new CTreesTest();
    test->testBalancedBinaryTree();
    
	
	//[glView startAnimation];
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    //[glView stopAnimation];
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    //[glView startAnimation];
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    //[glView stopAnimation];
}

- (void)dealloc
{
    [window release];
    [glView release];

    [super dealloc];
}

@end
